package com.wjf.shortlink.shortlink.common.convention.exception;

import com.wjf.shortlink.shortlink.common.convention.errorcode.IErrorCode;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.springframework.util.StringUtils;

import java.util.Optional;

// 抽象项目异常
@Getter
public abstract class AbstractException extends RuntimeException {
    public final String errorCode;
    public final String errorMessage;

    public AbstractException(String errorMessage, Throwable throwable, IErrorCode iErrorCode) {
        super(errorMessage, throwable);
        this.errorCode = iErrorCode.code();
        this.errorMessage = Optional.ofNullable(StringUtils.hasLength(errorMessage) ? errorMessage : null)
                .orElse(iErrorCode.message());

    }
}
